package com.lc.cehui.ui.fragment.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.cehui.R;
import com.lc.cehui.app.AppFragment;
import com.lc.cehui.http.request.CompanyListJobApi;
import com.lc.cehui.http.response.CompanyListJobBean;
import com.lc.cehui.ui.activity.home.ParticularsActivity;
import com.lc.cehui.ui.activity.home.ParticularsDetailsActivity;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

public class ParticularsPositionFragment extends AppFragment<ParticularsActivity> {
    private static final String ARG_PARAM1 = "param1";
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private BaseQuickAdapter adapter;
    List<CompanyListJobBean.DataBean> dataList = new ArrayList<>();
    private String system_id;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_particularsposition;
    }

    @Override
    protected void initView() {
        adapter = new BaseQuickAdapter<CompanyListJobBean.DataBean, BaseViewHolder>
                (R.layout.item_gongsizhiwei,dataList) {

            @Override
            protected void convert(BaseViewHolder baseViewHolder,CompanyListJobBean.DataBean dataBean) {
                baseViewHolder.setText(R.id.tv_name,dataBean.getTitle());
                baseViewHolder.setText(R.id.tv_tag, dataBean.getWork_city()+ dataBean.getWork_district()+"  ｜  "+dataBean.getYears()+"  ｜  "+ dataBean.getEducation());
                baseViewHolder.setText(R.id.tv_salary,dataBean.getSalary());
                RecyclerView recyclerView2=baseViewHolder.getView(R.id.recyclerView2);

                BaseQuickAdapter<CompanyListJobBean.DataBean.WelfareBean, BaseViewHolder> adapter=new BaseQuickAdapter<CompanyListJobBean.DataBean.WelfareBean, BaseViewHolder>(R.layout.item_gongsifuli2,dataBean.getWelfare()) {
                    @Override
                    protected void convert(@NotNull BaseViewHolder holder, CompanyListJobBean.DataBean.WelfareBean item) {
                        holder.setText(R.id.tv_name,item.getWelfare());
                    }
                };
                recyclerView2.setAdapter(adapter);
            }


        };
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {
                startActivity(new Intent(getContext(), ParticularsDetailsActivity.class).putExtra("company_id",system_id).putExtra("job_id",dataList.get(position).getJob_id()+""));
            }
        });
    }
    public static ParticularsPositionFragment newInstance(String system_id) {
        ParticularsPositionFragment fragment = new ParticularsPositionFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, system_id);

        fragment.setArguments(args);
        return fragment;
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            system_id = getArguments().getString(ARG_PARAM1);

        }
    }
    @Override
    protected void initData() {
        company_listjob();

    }

    private void company_listjob() {
        EasyHttp.post(this)
                .api(new CompanyListJobApi().setCompany_id(system_id).setPage(1))
                .request(new HttpCallback<CompanyListJobBean>(this) {
                    @Override
                    public void onSucceed(CompanyListJobBean data) {
                        dataList.addAll(data.getData());
                        adapter.setNewData(dataList);
                        adapter.notifyDataSetChanged();

                    }
                });
    }
}
